using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ShopSaleOrderView : Admin, IRequiresSessionState
{
	protected TextBox TextBox1;
	protected DropDownList DropDownList1;
	protected DropDownList DropMoment;
	protected TextBox TxtProductName;
	protected TextBox TxtBeginDate;
	protected TextBox TxtEndDate;
	protected Button Button1;
	protected GridView GridView1;
	private string wherestr = "";
	private ArrayList al = new ArrayList();
	private IDbDataParameter[] param = null;
	private UserBll _userBll = null;
	private Shop_Order _shop_order = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected UserBll saler
	{
		get
		{
			UserBll userBll;
			if (this._userBll == null)
			{
				this._userBll = new UserBll(this.conn);
				userBll = this._userBll;
			}
			else
			{
				userBll = this._userBll;
			}
			return userBll;
		}
	}
	protected Shop_Order shop_order
	{
		get
		{
			Shop_Order shop_order;
			if (this._shop_order == null)
			{
				this._shop_order = new Shop_Order(this.conn);
				shop_order = this._shop_order;
			}
			else
			{
				shop_order = this._shop_order;
			}
			return shop_order;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(22))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Order");
			base.WriteRightErrMsg();
		}
		this.TxtBeginDate.Attributes.Add("onClick", "SelectDate(" + this.TxtBeginDate.UniqueID + ",'yyyy-MM-dd');");
		this.TxtEndDate.Attributes.Add("onClick", "SelectDate(" + this.TxtEndDate.UniqueID + ",'yyyy-MM-dd');");
		if (!base.IsPostBack)
		{
			if (this.TxtBeginDate.Text == "")
			{
				this.TxtBeginDate.Text = "2006-01-01";
			}
			if (this.TxtEndDate.Text == "")
			{
				this.TxtEndDate.Text = DateTime.Now.AddDays(1.0).ToShortDateString();
			}
			this.BindDate();
		}
	}
	private void strwhere()
	{
		this.wherestr = "and ((TradeType=2 and Status=1) or (TradeType=3 and Status=1) or (TradeType<>2 and TradeType<>3)) ";
		string text = this.TxtBeginDate.Text;
		if (text != string.Empty)
		{
			if (!Text.IsDate(text))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			this.wherestr += "and DateDiff(dd,updateTime, @BeginDate)<=0 ";
			this.al.Add(this.conn.CreateParameter("@BeginDate", DbType.DateTime, text));
		}
		string text2 = this.TxtEndDate.Text;
		if (text2 != string.Empty)
		{
			if (!Text.IsDate(text2))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (text != string.Empty)
			{
				if (Convert.ToDateTime(text) > Convert.ToDateTime(text2))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			this.wherestr += "and DateDiff(dd,updateTime, @EndDate)>=0 ";
			this.al.Add(this.conn.CreateParameter("@EndDate", DbType.DateTime, text2));
		}
		string text3 = this.TxtProductName.Text.Trim();
		if (text3 != string.Empty)
		{
			this.wherestr += "and ProductName like '%'+ @ProductName +'%' ";
			this.al.Add(this.conn.CreateParameter("@ProductName", DbType.String, text3.Trim()));
		}
		string selectedValue = this.DropMoment.SelectedValue;
		if (selectedValue != string.Empty)
		{
			string text4 = selectedValue;
			if (text4 != null)
			{
				if (!(text4 == "7"))
				{
					if (!(text4 == "10"))
					{
						if (!(text4 == "30"))
						{
							if (text4 == "365")
							{
								this.wherestr += "and DateDiff(dd,UpdateTime,getdate())<=365";
							}
						}
						else
						{
							this.wherestr += "and DateDiff(dd,UpdateTime, getdate())<=30 ";
						}
					}
					else
					{
						this.wherestr += "and DateDiff(dd,UpdateTime, getdate())<=10 ";
					}
				}
				else
				{
					this.wherestr += "and DateDiff(dd,UpdateTime, getdate())<=7 ";
				}
			}
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "");
		}
	}
	private void BindDate()
	{
		this.strwhere();
		if (this.al.Count > 0)
		{
			this.param = new IDbDataParameter[this.al.Count];
			this.al.CopyTo(this.param, 0);
		}
		this.GridView1.DataSource = this.shop_order.getproductSaleCount(this.wherestr, int.Parse(this.DropDownList1.SelectedValue), this.param);
		this.GridView1.DataBind();
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
		e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
	}
	protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindDate();
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		this.BindDate();
	}
	protected void TextBox1_TextChanged(object sender, EventArgs e)
	{
		this.AddUserDropDownList();
	}
	protected void AddUserDropDownList()
	{
		if (this.TextBox1.Text != "")
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@UserName", DbType.String, this.TextBox1.Text);
			IDataReader reader = this.conn.GetReader("Select UserID From [HL_User] Where ([UserName] = @UserName)", new IDbDataParameter[]
			{
				dbDataParameter
			});
			int num = 0;
			if (reader.Read())
			{
				num = Convert.ToInt32(reader["UserID"]);
				reader.Close();
				reader.Dispose();
				if (num != 0)
				{
					foreach (ListItem listItem in this.DropDownList1.Items)
					{
						if (listItem.Text.Trim() == this.TextBox1.Text.Trim())
						{
							return;
						}
					}
					ListItem item = new ListItem(this.TextBox1.Text, num.ToString());
					this.DropDownList1.Items.Add(item);
					this.DropDownList1.SelectedValue = num.ToString();
				}
			}
			else
			{
				reader.Close();
				reader.Dispose();
			}
		}
	}
}
